﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <script src="~/plugins/mzui/js/mzui.min.js"></script>
    <link href="~/plugins/mzui/css/mzui.min.css" rel="stylesheet" />
    <title>下单</title>
</head>
<body class="with-nav-bottom">
    <!-- 标题栏 -->
    <div class="heading">
        <div class="title text-center"><strong>提交订单</strong></div>
    </div>
    <div class="section">
        <table class="table bordered">
            <tbody>
                <tr>
                    <td colspan="2">会员手机号</td>
                    <td colspan="2">
                        <input id="user" type="text" class="input" onkeyup="value=value.replace(/[^\d]/g,'');" placeholder="买单人注册的手机号">
                    </td>
                </tr>
                <tr class="info">
                    <td>最惠待遇</td>
                    <td>折扣</td>
                    <td>消费金额</td>
                    <td>支付金额</td>
                </tr>
                @foreach (var item in Model)
                {
                    <tr>
                        <td name="name">@item.name</td>
                        <td name="mingzhe">@item.mingzhe</td>
                        <td>
                            <input name="rmb" type="text" onchange="setrmb();" onkeyup="value=value.replace(/[^\d]/g,'');" style="width:58px;">
                        </td>
                        <td name="pay">0</td>
                        <td name="anzhe" class="hidden">@item.anzhe</td>
                        <td name="zk" class="hidden">0</td>
                    </tr>
                }
                <tr>
                    <td class="text-right">消费原价</td>
                    <td id="amount" class="text-right">0</td>
                    <td class="text-right">折扣后金额</td>
                    <td id="rmb" class="text-blue">0</td>
                    <td id="ptf" class="hidden">0</td>
                </tr>
            </tbody>
        </table>
        <div class="title"><strong>&nbsp;&nbsp;&nbsp;注意事件</strong></div>
        <div class="divider"></div>
        <div class="radio inline-block box">
            订单需要会员在半小时之内支付,否则会失效.提交订单时候请核对金额.
            <br />
            发送以后,让会员进入会员中心点 在线结账
            <br />
            付款最终是否成功请刷新订单状态为准,不要已会员付款界面为准.
        </div>
        <div class="heading">
            <div class="title primary text-center" onclick="pay();"><strong>发送给会员</strong></div>
        </div>
        <div id="zhekou" class="radio inline-block box"></div>
    </div>
    <nav class="nav affix dock-bottom justified">
        <a href="/shop/hyxf?lx=0">支付结果</a>
        <a onclick="history.go(-1);" class="primary"><i class="icon-5x icon-arrow-left"></i></a>
    </nav>
    <script>
        function setrmb()
        {
            var amount = 0;
            var rmb = 0;
            var ptf = 0;
            document.getElementById("zhekou").innerHTML = "";
            for (var i = 0; i < document.getElementsByName("name").length; i++) {
                if (document.getElementsByName("rmb")[i].value > 0) {
                    amount += Number(document.getElementsByName("rmb")[i].value);
                    var pay = Math.round(document.getElementsByName("rmb")[i].value * document.getElementsByName("mingzhe")[i].innerHTML);
                    rmb += pay;
                    document.getElementsByName("pay")[i].innerHTML = pay;
                    var anzhe = Math.round(document.getElementsByName("rmb")[i].value * document.getElementsByName("anzhe")[i].innerHTML);
                    ptf += anzhe;
                    document.getElementsByName("zk")[i].innerHTML = anzhe;
                    document.getElementById("zhekou").innerHTML += document.getElementsByName("name")[i].innerHTML + ":" + document.getElementsByName("rmb")[i].value + " x " + document.getElementsByName("mingzhe")[i].innerHTML + " 折 =" + pay + "<br>";
                }
                else
                {
                    document.getElementsByName("pay")[i].innerHTML = 0;
                    document.getElementsByName("zk")[i].innerHTML = 0;
                }
            }
            document.getElementById("amount").innerHTML = amount;
            document.getElementById("rmb").innerHTML = rmb;
            document.getElementById("ptf").innerHTML = ptf;
        }
        function pay() {
            if (document.getElementById("user").value.length == 11) {
                $.ajax({
                    url: "/ajax/api.ashx",
                    data: "ff=tjr&tjr=" + document.getElementById("user").value + "&lx=0&Cache=" + Math.random(),
                    type: "post",
                    cache: false,
                    timeout: 8000,
                    dataType: "json",
                    ContentType: "application/json; charset=utf-8",
                    async: false,//一定要是同步请求，否则会跳转；（ajax默认是异步的）
                    error: function () { alert("AJAX Error"); },
                    beforeSend: function () { },
                    success: function (data) {
                        if (data.result == 200) {
                            $.ajax({
                                url: "/ajax/api.ashx",
                                data: "ff=shoppay&usergid=" + data.data + "&ptf=" + document.getElementById("ptf").innerHTML + "&rmb=" + document.getElementById("rmb").innerHTML + "&amount=" + document.getElementById("amount").innerHTML + "&zhekou=" + document.getElementById("zhekou").innerHTML + "&Cache=" + Math.random(),
                                type: "post",
                                cache: false,
                                timeout: 8000,
                                dataType: "json",
                                ContentType: "application/json; charset=utf-8",
                                async: false,//一定要是同步请求，否则会跳转；（ajax默认是异步的）
                                error: function () { alert("AJAX Error"); },
                                beforeSend: function () { },
                                success: function (data) {
                                    if (data.result == 200) {
                                        self.location = "/shop/hyxf?lx=0";
                                    }
                                    else {
                                        alert(data.data);
                                    }
                                },
                            });
                        }
                        else {
                            document.getElementById("user").value = "";
                            alert(data.data);
                        }
                    },
                });
            }
            else {
                document.getElementById("user").value = "";
                alert("请输入买单会员注册的手机号");
            }
        }
    </script>
</body>
</html>
